﻿//var thisid=location.href.match(/(thisid=)([0-9a-zA-Z]+)/).splice("=")[2];
//陌生人30条
var currentIndex=1;//分页
var pageSize=30;//个数
var canscroll="yes";
var ajurl=usernewsurl;//默认为最新30条(单身......)

if(/isstrange/.test(location.href)){
    $("#waiting").remove();
}
var thisid;
if($.cookie("otherid")){
    thisid=$.cookie("otherid");
}else{
    thisid=id;
}
var whoname="";
//页面返回------------------------------------------------
$(".mweb_modal_back_button").click(function(){
    history.go(-1);
});
//经验金钱判断能否进入------------------------------------ href='http://www.pulu.com/weixin/newsdetail.html?newsid="+data[i].qid+"#fromuser="+id+"#newsShareId="+data[i].shareId+"'
function moneytest(e){
    //判断能不能去看详情页
    var thiseid= e.dataset.eid;
    $.cookie("lastInfoScroll",$(window).scrollTop());
    $.cookie("lastInfoIndex",currentIndex);
    var thistype=e.dataset.type;
    if(thistype=="1"){
        var errorUrl=/环球网|1905电影网|中国会计视野|编织人生网|IT之家|优姿美女/;
        if(e.dataset.sitename){
            if(errorUrl.test(e.dataset.sitename)){
                location.href="http://www.pulu.com/weixin/newsdetail.html?newsid="+thiseid+"#fromuser="+id+"#newsShareId="+e.dataset.shareid;
            }
            else{
                location.href="newsdetail.html?newsid="+thiseid+"#fromuser="+id+"#newsShareId="+e.dataset.shareid;
            }
        }
    }else if(thistype=="2"){
        location.href='questiondetail.html?qid='+thiseid+"#fromuser="+id;
    }else if(thistype=="3"){
        location.href='shareexppage.html?eid='+thiseid+"#fromuser="+id
    }
}
//去充值
$("#okgobtn").click(function(){
    location.href="scoredetial.html";
});
//取消
$("#cancel").click(function(){
    $("body").css("overflow","auto");
    $(".moneyinfomob").css("display","none");
});
//加载最新动态方法------------------------------------------
var lastTime="";//上一次的时间
function aj(Index,Size){
    canscroll="no";
    $.ajax({
        type:"get",
        datatype:"json",
        url:ajurl+thisid+"&currentIndex="+Index+"&pageSize="+Size,
        success:function(d){
            var data= d.Data;
            canscroll="yes";
            if(data&&data.length>0){
                if(data.length<pageSize){
                    //$("#loading").remove();
                    $("#waiting").css("display","none");
                    $("#nonews").css("display","block");
                    canscroll="no";
                }
                for(var i=0;i<data.length;i++){
                    if(data[i].title){
                        //时间--------------------
                        var dataarr=data[i].cTime.split("-");
                        var monthnum=dataarr[1];//月
                        //console.log(dataarr);
                        var daynum=dataarr[2].match(/^[0-9]+/)[0];//日
                        var newlastTime=daynum+monthnum;
                        var lfStyle="";
                        var rtStyle="";
                        if(newlastTime==lastTime){
                            lfStyle="style='display:none;'";
                            rtStyle="style='margin-top:-31px;'";
                        }else{
                            lastTime=newlastTime;
                        }
                        //是否有评论--------------
                        var statusword="";
                        if(data[i].des||data[i].answerContent){
                            var word=data[i].des||data[i].answerContent;
                            var newword=codetoface(word);
                            statusword="<div class='status'>"+newword+"</div>";
                        }
                        //是否有钱----------------
                        var score="";
                        if(data[i].score){
                            score="<span style='color:#f4c600;padding-left:5px;'><img src='../img/money04.png' style='width:12px;height:13px;margin-top:-3px;'>"+parseFloat(data[i].score)/100+"</span>"
                        }
                        //图片
                        var imgplace="";
                        var stylechange='';
                        if(data[i].imgurl){
                            stylechange='style="margin-left:55px;"'
                            imgplace="<div class='lf'><img src='"+imgurl+data[i].imgurl+"'></div>";
                        }
                        //资讯--------------------
                        if(data[i].type=="1"){
                            if(data[i].imgurl){
                                imgplace="<div class='lf'><img src='"+data[i].imgurl+"'></div>";
                            }
                            $("#mainbodyplace").append("<div class='listbox' "+rtStyle+"><div class='leftplace' "+lfStyle+"><span class='day'>"+daynum+"</span><span class='month'>"+monthnum+"</span> <span class='monthword'>月</span></div><div class='rightplace'><div class='rightplacebox'><a data-type='1' data-eid='"+data[i].qid+"' data-sitename='"+data[i].sitename+"' data-shareid='"+data[i].shareId+"' onclick='moneytest(this)'><div class='title'><span class='who'>"+whoname+" </span><span class='how'>"+data[i].operateTypeName+"</span> <span class='what'>资讯</span></div>"+statusword+"<div class='info'>"+imgplace+"<div "+stylechange+">"+data[i].title+"</div></div></div></a></div></div>");
                        }
                        //问题--------------------
                        else if(data[i].type=="2"){
                            var tit="";
                            if(data[i].title){
                                tit=codetoface(data[i].title);
                            }
                            $("#mainbodyplace").append("<div class='listbox' "+rtStyle+"><div class='leftplace' "+lfStyle+"> <span class='day'>"+daynum+"</span> <span class='month'>"+monthnum+"</span> <span class='monthword'>月</span></div><div class='rightplace'> <div class='rightplacebox'> <a data-type='2' data-eid='"+data[i].qid+"' onclick='moneytest(this)'><div class='title'> <span class='who'>"+whoname+" </span><span class='how'>"+data[i].operateTypeName+"</span> <span class='what'>悬赏</span>"+score+"</div>"+statusword+"<div class='info'>"+imgplace+"<div "+stylechange+">"+tit+"</div></div></div></a></div></div>");              //评论
                        }
                        //经验 单身---------------
                        else{
                            if(thisid!=$.cookie("MYID")){
                                imgplace="";
                                stylechange="";
                            }
                            var tit="";
                            var typeName="";
                            if(data[i].type==3){typeName="经验"}
                            else if(data[i].type==4){typeName="单身资源"}
                            else if(data[i].type==5){typeName="电影评论"}
                            else if(data[i].type==6){typeName="工作机会"}
                            else if(data[i].type==7){typeName="租房买卖"}
                            else if(data[i].type==8){typeName="项目资源"}
                            else if(data[i].type==9){typeName="人脉资源"}
                            else if(data[i].type==10){typeName="其他资源"}
                            tit=codetoface(data[i].title);
                            $("#mainbodyplace").append("<div class='listbox' "+rtStyle+"><div class='leftplace' "+lfStyle+"> <span class='day'>"+daynum+"</span> <span class='month'>"+monthnum+"</span> <span class='monthword'>月</span></div><div class='rightplace'> <div class='rightplacebox'><a data-type='3' data-eid='"+data[i].qid+"' onclick='moneytest(this)'> <div class='title'> <span class='who'>"+whoname+" </span><span class='how'>"+data[i].operateTypeName+"</span> <span class='what'>"+typeName+"</span>"+score+"</div>"+statusword+"<div class='info'>"+imgplace+"<div "+stylechange+">"+tit+"</div></div></div></a></div></div>");
                            //经验金额               经验ID                               经验发布者
                        }
                    }

                }
            }
            else{
                $("#waiting").css("display","none");
                $("#nonews").css("display","block");
                canscroll="no";
            }
            if(/[0-9]+/.test($.cookie("lastInfoIndex"))){
                currentIndex=$.cookie("lastInfoIndex");
                pageSize=30;
                $(window).scrollTop($.cookie("lastInfoScroll"));
                $.cookie("lastInfoIndex","");
                $.cookie("lastInfoScroll","");

            }
        }
    })
}
$().ready(function(){

    var id= $.cookie("MYID");
    if(/[0-9]+/.test($.cookie("lastInfoIndex"))){
        currentIndex=1;
        pageSize=parseInt($.cookie("lastInfoIndex"))*30;
    }
    if(thisid==id){
        whoname="您";
        if($.cookie("setpageLastNoteType")=="last"){
            ajurl=usernewsurl;
        }else if($.cookie("setpageLastNoteType")=="goResource"){
            $(".page_title").html("个人资源");
            ajurl=myRes;
        }else{
            ajurl=usernewsurl;
        }
        aj(currentIndex,pageSize);
    }else{
        $.ajax({
            type: "post",
            url: userurl,
            data: { "userId": thisid },
            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
            success:function(d){
                whoname= d.Data.userNick;
                //获取用户信息及最新动态-----------------------------------
                aj(currentIndex,pageSize);
            }
        });
    }
});
//页面滚动加载-------------------------------------------------
$(window).scroll(function(){
    if(!/isstrange/.test(location.href)){
        var mainheight=$("#page_wrapper").height();
        var windowheight=$(window).height();
        var chajuli=$("#page_wrapper").offset().top - $(window).scrollTop();
        var scrollheight=$(window).scrollTop();
        var cz=windowheight-mainheight+5;
        if(canscroll==="yes"){
            if(chajuli<cz){
                currentIndex++;
                aj(currentIndex,pageSize);
            }
        }
    }
});